export const  ClientTypes =  {
    wps: "wps",
    et: "et",
    wpp: "wpp"
}

/**
 * 获取网页路径前缀
 * @returns url前缀
 */
const GetUrlBase = () => {
    // if (location.protocol == "https:")
    //   return "https://127.0.0.1:58891"
    return "http://127.0.0.1:58890"
}

let getHttpObj=()=>{
    return new XMLHttpRequest();
}



let fromCharCode = String.fromCharCode;
// encoder stuff
let cb_utob = (c)=>{
  if (c.length < 2) {
    let cc = c.charCodeAt(0);
    return cc < 0x80 ? c :
      cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6)) +
          fromCharCode(0x80 | (cc & 0x3f))) :
        (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) +
          fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
          fromCharCode(0x80 | (cc & 0x3f)));
  } else {
    let cc = 0x10000 +
      (c.charCodeAt(0) - 0xD800) * 0x400 +
      (c.charCodeAt(1) - 0xDC00);
    return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07)) +
      fromCharCode(0x80 | ((cc >>> 12) & 0x3f)) +
      fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
      fromCharCode(0x80 | (cc & 0x3f)));
  }
};
let re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
let utob = function (u) {
  return u.replace(re_utob, cb_utob);
};
let _encode = (u) => {
  let isUint8Array = Object.prototype.toString.call(u) === '[object Uint8Array]';
  if (isUint8Array)
    return u.toString('base64')
  else
    return btoa(utob(String(u)));
}

/**
 * 将字符串进行Base64编码
 * @param {*} u         需要编码的数据
 * @param {*} urisafe   返回值，编码后的数据
 * @returns             urisafe
 */
let encode = function (u, urisafe) {
  return !urisafe ?
    _encode(u) :
    _encode(String(u)).replace(/[+\/]/g, function (m0) {
      return m0 == '+' ? '-' : '_';
    }).replace(/=/g, '');
};

export {
    GetUrlBase,getHttpObj,encode
}
